﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using TradingAppDal;

namespace TradingApp.Helper
{
    public class XmlHelper
    {
        public const string SettingsFile = "AdminSettings.xml";
        public static int GetIntTagValue(string tagName)
        {
            UIHelper.ChangeToCurrentDirectory();
            
            XmlDocument xSettingsDoc = new XmlDocument();
            xSettingsDoc.Load(SettingsFile);

            XmlNodeList oPoolInterval = xSettingsDoc.SelectNodes(@"/Settings/" + tagName);
            if (oPoolInterval[0].InnerText != "")
            {
                return Convert.ToInt32(oPoolInterval[0].InnerText);
            }
            else
            {
                return TradingAppSettings.DefaultIntValue;
            }
        }
        
        public static string GetStringTagValue(string tagName)
        {
            UIHelper.ChangeToCurrentDirectory();

            XmlDocument xSettingsDoc = new XmlDocument();
            xSettingsDoc.Load(SettingsFile);

            XmlNodeList oPoolInterval = xSettingsDoc.SelectNodes(@"/Settings/" + tagName);
            return oPoolInterval[0].InnerText;
        }
        public static void SetTagValue(string tagName,string tagValue)
        {
            UIHelper.ChangeToCurrentDirectory();

            XmlDocument xSettingsDoc = new XmlDocument();
            xSettingsDoc.Load(SettingsFile);

            XmlNodeList ooPoolInterval = xSettingsDoc.SelectNodes(@"/Settings/" + tagName);
            ooPoolInterval[0].InnerText = tagValue;
            xSettingsDoc.Save(SettingsFile);
        }
        
    }
}
